package com.webrtc.config.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Iterator;
import java.util.Map;

/**
 * @author liuzhiqiang
 */
@Configuration
@EnableScheduling
@Slf4j
public class Task {

    @Scheduled(cron = "0/1 * * * * ? ")
    public void task() {
        Iterator<Map.Entry<String, TargetUser>> it = LoginResources.loginUser.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<String, TargetUser> entry = it.next();
            entry.getValue().setTime(entry.getValue().getTime() + 1L);
            if (entry.getValue().getTime() > 10) {
                log.info("销毁一个连接：{}",entry.getKey());
                LoginResources.loginUser.remove(entry.getKey());
            }
        }
    }
}
